<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content=
    "application/xhtml+xml; charset=iso-8859-1" />
    <title>
      6.17.&nbsp;GCC-4.7.2
    </title>
    <link rel="stylesheet" href="../stylesheets/lfs.css" type="text/css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
    <link rel="stylesheet" href="../stylesheets/lfs-print.css" type=
    "text/css" media="print" />
  </head>
  <body class="lfs" id="lfs-7.3">
    <div class="navheader">
      <h4>
        Linux From Scratch - Version 7.3
      </h4>
      <h3>
        Chapter&nbsp;6.&nbsp;Installing Basic System Software
      </h3>
      <ul>
        <li class="prev">
          <a accesskey="p" href="mpc.html" title="MPC-1.0.1">Prev</a>
          <p>
            MPC-1.0.1
          </p>
        </li>
        <li class="next">
          <a accesskey="n" href="sed.html" title="Sed-4.2.2">Next</a>
          <p>
            Sed-4.2.2
          </p>
        </li>
        <li class="up">
          <a accesskey="u" href="chapter06.html" title=
          "Chapter&nbsp;6.&nbsp;Installing Basic System Software">Up</a>
        </li>
        <li class="home">
          <a accesskey="h" href="../index.html" title=
          "Linux From Scratch - Version 7.3">Home</a>
        </li>
      </ul>
    </div>
    <div class="wrap" lang="en" xml:lang="en">
      <h1 class="sect1">
        <a id="ch-system-gcc" name="ch-system-gcc"></a>6.17. GCC-4.7.2
      </h1>
      <div class="package" lang="en" xml:lang="en">
        <p>
          The GCC package contains the GNU compiler collection, which
          includes the C and C++ compilers.
        </p>
        <div class="segmentedlist">
          <div class="seglistitem">
            <div class="seg">
              <strong class="segtitle">Approximate build time:</strong>
              <span class="segbody">53.5 SBU</span>
            </div>
            <div class="seg">
              <strong class="segtitle">Required disk space:</strong>
              <span class="segbody">2.0 GB</span>
            </div>
          </div>
        </div>
      </div>
      <div class="installation" lang="en" xml:lang="en">
        <h2 class="sect2">
          6.17.1. Installation of GCC
        </h2>
        <p>
          Apply a <span class="command"><strong>sed</strong></span>
          substitution that will suppress the installation of <code class=
          "filename">libiberty.a</code>. The version of <code class=
          "filename">libiberty.a</code> provided by Binutils will be used
          instead:
        </p>
        <pre class="userinput">
<kbd class=
"command">sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in</kbd>
</pre>
        <p>
          Again, do not build the .info files. They are broken with the
          current version of <span class=
          "command"><strong>makeinfo</strong></span>.
        </p>
        <pre class="userinput">
<kbd class=
"command">sed -i 's/BUILD_INFO=info/BUILD_INFO=/' gcc/configure</kbd>
</pre>
        <p>
          As in <a class="xref" href="../chapter05/gcc-pass2.html" title=
          "5.9.&nbsp;GCC-4.7.2 - Pass 2">Section&nbsp;5.9, &ldquo;GCC-4.7.2 -
          Pass 2&rdquo;</a>, apply the following <span class=
          "command"><strong>sed</strong></span> to force the build to use the
          <code class="option">-fomit-frame-pointer</code> compiler flag in
          order to ensure consistent compiler builds:
        </p>
        <pre class="userinput">
<kbd class="command">case `uname -m` in
  i?86) sed -i 's/^T_CFLAGS =$/&amp; -fomit-frame-pointer/' gcc/Makefile.in ;;
esac</kbd>
</pre>
        <p>
          Also fix an error in one of the check Makefiles:
        </p>
        <pre class="userinput">
<kbd class=
"command">sed -i -e /autogen/d -e /check.sh/d fixincludes/Makefile.in</kbd>
</pre>
        <p>
          The GCC documentation recommends building GCC outside of the source
          directory in a dedicated build directory:
        </p>
        <pre class="userinput">
<kbd class="command">mkdir -v ../gcc-build
cd ../gcc-build</kbd>
</pre>
        <p>
          Prepare GCC for compilation:
        </p>
        <pre class="userinput">
<kbd class="command">../gcc-4.7.2/configure --prefix=/usr            \
                       --libexecdir=/usr/lib    \
                       --enable-shared          \
                       --enable-threads=posix   \
                       --enable-__cxa_atexit    \
                       --enable-clocale=gnu     \
                       --enable-languages=c,c++ \
                       --disable-multilib       \
                       --disable-bootstrap      \
                       --with-system-zlib</kbd>
</pre>
        <p>
          Note that for other languages, there are some prerequisites that
          are not available. See the BLFS Book for instructions on how to
          build all the GCC supported languages.
        </p>
        <div class="variablelist">
          <p class="title">
            <b>The meaning of the new configure option:</b>
          </p>
          <dl>
            <dt>
              <span class="term"><em class=
              "parameter"><code>--with-system-zlib</code></em></span>
            </dt>
            <dd>
              <p>
                This switch tells GCC to link to the system installed copy of
                the Zlib library, rather than its own internal copy.
              </p>
            </dd>
          </dl>
        </div>
        <div class="admon note">
          <img alt="[Note]" src="../images/note.png" />
          <h3>
            Note
          </h3>
          <p>
            There is an optional argument to <span class=
            "command"><strong>configure</strong></span>, <code class=
            "option">--enable-lto</code>, that can be used to allow
            <span class="command"><strong>gcc</strong></span> to do do "link
            time optimization" if specified. No packages in LFS or BLFS
            currently use this capability.
          </p>
          <p>
            To use this feature, it must also be enabled in <span class=
            "application">binutils</span>.
          </p>
        </div>
        <p>
          Compile the package:
        </p>
        <pre class="userinput">
<kbd class="command">make</kbd>
</pre>
        <div class="admon important">
          <img alt="[Important]" src="../images/important.png" />
          <h3>
            Important
          </h3>
          <p>
            In this section, the test suite for GCC is considered critical.
            Do not skip it under any circumstance.
          </p>
        </div>
        <p>
          One set of tests in the GCC test suite is known to exhaust the
          stack, so increase the stack size prior to running the tests:
        </p>
        <pre class="userinput">
<kbd class="command">ulimit -s 32768</kbd>
</pre>
        <p>
          Test the results, but do not stop at errors:
        </p>
        <pre class="userinput">
<kbd class="command">make -k check</kbd>
</pre>
        <p>
          To receive a summary of the test suite results, run:
        </p>
        <pre class="userinput">
<kbd class="command">../gcc-4.7.2/contrib/test_summary</kbd>
</pre>
        <p>
          For only the summaries, pipe the output through <strong class=
          "userinput"><code>grep -A7 Summ</code></strong>.
        </p>
        <p>
          Results can be compared with those located at <a class="ulink"
          href="http://www.linuxfromscratch.org/lfs/build-logs/7.3/">http://www.linuxfromscratch.org/lfs/build-logs/7.3/</a>
          and <a class="ulink" href=
          "http://gcc.gnu.org/ml/gcc-testresults/">http://gcc.gnu.org/ml/gcc-testresults/</a>.
        </p>
        <p>
          A few unexpected failures cannot always be avoided. The GCC
          developers are usually aware of these issues, but have not resolved
          them yet. In particular, the <code class=
          "filename">libmudflap</code> tests are known to be particularly
          problematic as a result of a bug in GCC (<a class="ulink" href=
          "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20003">http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20003</a>).
          Unless the test results are vastly different from those at the
          above URL, it is safe to continue.
        </p>
        <p>
          Install the package:
        </p>
        <pre class="userinput">
<kbd class="command">make install</kbd>
</pre>
        <p>
          Some packages expect the C preprocessor to be installed in the
          <code class="filename">/lib</code> directory. To support those
          packages, create this symlink:
        </p>
        <pre class="userinput">
<kbd class="command">ln -sv ../usr/bin/cpp /lib</kbd>
</pre>
        <p>
          Many packages use the name <span class=
          "command"><strong>cc</strong></span> to call the C compiler. To
          satisfy those packages, create a symlink:
        </p>
        <pre class="userinput">
<kbd class="command">ln -sv gcc /usr/bin/cc</kbd>
</pre>
        <p>
          Now that our final toolchain is in place, it is important to again
          ensure that compiling and linking will work as expected. We do this
          by performing the same sanity checks as we did earlier in the
          chapter:
        </p>
        <pre class="userinput">
<kbd class="command">echo 'main(){}' &gt; dummy.c
cc dummy.c -v -Wl,--verbose &amp;&gt; dummy.log
readelf -l a.out | grep ': /lib'</kbd>
</pre>
        <p>
          If everything is working correctly, there should be no errors, and
          the output of the last command will be (allowing for
          platform-specific differences in dynamic linker name):
        </p>
        <pre class="screen">
<code class=
"computeroutput">[Requesting program interpreter: /lib/ld-linux.so.2]</code>
</pre>
        <p>
          Now make sure that we're setup to use the correct startfiles:
        </p>
        <pre class="userinput">
<kbd class="command">grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log</kbd>
</pre>
        <p>
          If everything is working correctly, there should be no errors, and
          the output of the last command will be:
        </p>
        <pre class="screen">
<code class=
"computeroutput">/usr/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../crt1.o succeeded
/usr/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../crti.o succeeded
/usr/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../crtn.o succeeded</code>
</pre>
        <p>
          Depending on your machine architecture, the above may differ
          slightly, the difference usually being the name of the directory
          after <code class="filename">/usr/lib/gcc</code>. If your machine
          is a 64-bit system, you may also see a directory named <code class=
          "filename">lib64</code> towards the end of the string. The
          important thing to look for here is that <span class=
          "command"><strong>gcc</strong></span> has found all three
          <code class="filename">crt*.o</code> files under the <code class=
          "filename">/usr/lib</code> directory.
        </p>
        <p>
          Verify that the compiler is searching for the correct header files:
        </p>
        <pre class="userinput">
<kbd class="command">grep -B4 '^ /usr/include' dummy.log</kbd>
</pre>
        <p>
          This command should return successfully with the following output:
        </p>
        <pre class="screen">
<code class="computeroutput">#include &lt;...&gt; search starts here:
 /usr/lib/gcc/i686-pc-linux-gnu/4.7.2/include
 /usr/local/include
 /usr/lib/gcc/i686-pc-linux-gnu/4.7.2/include-fixed
 /usr/include</code>
</pre>
        <p>
          Again, note that the directory named after your target triplet may
          be different than the above, depending on your architecture.
        </p>
        <div class="admon note">
          <img alt="[Note]" src="../images/note.png" />
          <h3>
            Note
          </h3>
          <p>
            As of version 4.3.0, GCC now unconditionally installs the
            <code class="filename">limits.h</code> file into the private
            <code class="filename">include-fixed</code> directory, and that
            directory is required to be in place.
          </p>
        </div>
        <p>
          Next, verify that the new linker is being used with the correct
          search paths:
        </p>
        <pre class="userinput">
<kbd class="command">grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g'</kbd>
</pre>
        <p>
          If everything is working correctly, there should be no errors, and
          the output of the last command (allowing for platform-specific
          target triplets) will be:
        </p>
        <pre class="screen">
<code class="computeroutput">SEARCH_DIR("/usr/i686-pc-linux-gnu/lib")
SEARCH_DIR("/usr/local/lib")
SEARCH_DIR("/lib")
SEARCH_DIR("/usr/lib");</code>
</pre>
        <p>
          A 64-bit system may see a few more directories. For example, here
          is the output from an x86_64 machine:
        </p>
        <pre class="screen">
<code class=
"computeroutput">SEARCH_DIR("/usr/x86_64-unknown-linux-gnu/lib64")
SEARCH_DIR("/usr/local/lib64")
SEARCH_DIR("/lib64")
SEARCH_DIR("/usr/lib64")
SEARCH_DIR("/usr/x86_64-unknown-linux-gnu/lib")
SEARCH_DIR("/usr/local/lib")
SEARCH_DIR("/lib")
SEARCH_DIR("/usr/lib");</code>
</pre>
        <p>
          Next make sure that we're using the correct libc:
        </p>
        <pre class="userinput">
<kbd class="command">grep "/lib.*/libc.so.6 " dummy.log</kbd>
</pre>
        <p>
          If everything is working correctly, there should be no errors, and
          the output of the last command (allowing for a lib64 directory on
          64-bit hosts) will be:
        </p>
        <pre class="screen">
<code class="computeroutput">attempt to open /lib/libc.so.6 succeeded</code>
</pre>
        <p>
          Lastly, make sure GCC is using the correct dynamic linker:
        </p>
        <pre class="userinput">
<kbd class="command">grep found dummy.log</kbd>
</pre>
        <p>
          If everything is working correctly, there should be no errors, and
          the output of the last command will be (allowing for
          platform-specific differences in dynamic linker name and a lib64
          directory on 64-bit hosts):
        </p>
        <pre class="screen">
<code class="computeroutput">found ld-linux.so.2 at /lib/ld-linux.so.2</code>
</pre>
        <p>
          If the output does not appear as shown above or is not received at
          all, then something is seriously wrong. Investigate and retrace the
          steps to find out where the problem is and correct it. The most
          likely reason is that something went wrong with the specs file
          adjustment. Any issues will need to be resolved before continuing
          on with the process.
        </p>
        <p>
          Once everything is working correctly, clean up the test files:
        </p>
        <pre class="userinput">
<kbd class="command">rm -v dummy.c a.out dummy.log</kbd>
</pre>
        <p>
          Finally, move a misplaced file:
        </p>
        <pre class="userinput">
<kbd class="command">mkdir -pv /usr/share/gdb/auto-load/usr/lib
mv -v /usr/lib/*gdb.py /usr/share/gdb/auto-load/usr/lib</kbd>
</pre>
      </div>
      <div class="content" lang="en" xml:lang="en">
        <h2 class="sect2">
          <a id="contents-gcc" name="contents-gcc"></a>6.17.2. Contents of
          GCC
        </h2>
        <div class="segmentedlist">
          <div class="seglistitem">
            <div class="seg">
              <strong class="segtitle">Installed programs:</strong>
              <span class="segbody">c++, cc (link to gcc), cpp, g++, gcc,
              gcc-ar, gcc-nm, gcc-ranlib, gccbug, and gcov</span>
            </div>
            <div class="seg">
              <strong class="segtitle">Installed libraries:</strong>
              <span class="segbody">libgcc.a, libgcc_eh.a, libgcc_s.so,
              libgcov.a, libgomp.{a,so}, liblto_plugin.so, libmudflap.{a,so},
              libmudflapth.{a,so}, libquadmath.{a,so}, libssp.{a,so},
              libssp_nonshared.a, libstdc++.{a,so} and libsupc++.a</span>
            </div>
            <div class="seg">
              <strong class="segtitle">Installed directories:</strong>
              <span class="segbody">/usr/include/c++, /usr/lib/gcc,
              /usr/share/gcc-4.7.2</span>
            </div>
          </div>
        </div>
        <div class="variablelist">
          <h3>
            Short Descriptions
          </h3>
          <table border="0">
            <col align="left" valign="top" />
            <tbody>
              <tr>
                <td>
                  <p>
                    <a id="c" name="c"></a><span class="term"><span class=
                    "command"><strong>c++</strong></span></span>
                  </p>
                </td>
                <td>
                  <p>
                    The C++ compiler
                  </p>
                </td>
              </tr>
              <tr>
                <td>
                  <p>
                    <a id="cc" name="cc"></a><span class="term"><span class=
                    "command"><strong>cc</strong></span></span>
                  </p>
                </td>
                <td>
                  <p>
                    The C compiler
                  </p>
                </td>
              </tr>
              <tr>
                <td>
                  <p>
                    <a id="cpp" name="cpp"></a><span class=
                    "term"><span class="command"><strong>cpp</strong></span></span>
                  </p>
                </td>
                <td>
                  <p>
                    The C preprocessor; it is used by the compiler to expand
                    the #include, #define, and similar statements in the
                    source files
                  </p>
                </td>
              </tr>
              <tr>
                <td>
                  <p>
                    <a id="g" name="g"></a><span class="term"><span class=
                    "command"><strong>g++</strong></span></span>
                  </p>
                </td>
                <td>
                  <p>
                    The C++ compiler
                  </p>
                </td>
              </tr>
              <tr>
                <td>
                  <p>
                    <a id="gcc" name="gcc"></a><span class=
                    "term"><span class="command"><strong>gcc</strong></span></span>
                  </p>
                </td>
                <td>
                  <p>
                    The C compiler
                  </p>
                </td>
              </tr>
              <tr>
                <td>
                  <p>
                    <a id="gcc-ar" name="gcc-ar"></a><span class=
                    "term"><span class=
                    "command"><strong>gcc-ar</strong></span></span>
                  </p>
                </td>
                <td>
                  <p>
                    A wrapper around <span class=
                    "command"><strong>ar</strong></span> that adds a plugin
                    to the command line. This program is only used to add
                    "link time optization" and is not useful with the default
                    build options.
                  </p>
                </td>
              </tr>
              <tr>
                <td>
                  <p>
                    <a id="gcc-nm" name="gcc-nm"></a><span class=
                    "term"><span class=
                    "command"><strong>gcc-nm</strong></span></span>
                  </p>
                </td>
                <td>
                  <p>
                    A wrapper around <span class=
                    "command"><strong>nm</strong></span> that adds a plugin
                    to the command line. This program is only used to add
                    "link time optization" and is not useful with the default
                    build options.
                  </p>
                </td>
              </tr>
              <tr>
                <td>
                  <p>
                    <a id="gcc-ranlib" name="gcc-ranlib"></a><span class=
                    "term"><span class=
                    "command"><strong>gcc-ranlib</strong></span></span>
                  </p>
                </td>
                <td>
                  <p>
                    A wrapper around <span class=
                    "command"><strong>ranlib</strong></span> that adds a
                    plugin to the command line. This program is only used to
                    add "link time optization" and is not useful with the
                    default build options.
                  </p>
                </td>
              </tr>
              <tr>
                <td>
                  <p>
                    <a id="gccbug" name="gccbug"></a><span class=
                    "term"><span class=
                    "command"><strong>gccbug</strong></span></span>
                  </p>
                </td>
                <td>
                  <p>
                    A shell script used to help create useful bug reports
                  </p>
                </td>
              </tr>
              <tr>
                <td>
                  <p>
                    <a id="gcov" name="gcov"></a><span class=
                    "term"><span class=
                    "command"><strong>gcov</strong></span></span>
                  </p>
                </td>
                <td>
                  <p>
                    A coverage testing tool; it is used to analyze programs
                    to determine where optimizations will have the most
                    effect
                  </p>
                </td>
              </tr>
              <tr>
                <td>
                  <p>
                    <a id="libgcc" name="libgcc"></a><span class=
                    "term"><code class="filename">libgcc</code></span>
                  </p>
                </td>
                <td>
                  <p>
                    Contains run-time support for <span class=
                    "command"><strong>gcc</strong></span>
                  </p>
                </td>
              </tr>
              <tr>
                <td>
                  <p>
                    <a id="libgcov" name="libgcov"></a><span class=
                    "term"><code class="filename">libgcov</code></span>
                  </p>
                </td>
                <td>
                  <p>
                    This library is linked in to a program when GCC is
                    instructed to enable profiling
                  </p>
                </td>
              </tr>
              <tr>
                <td>
                  <p>
                    <a id="libgomp" name="libgomp"></a><span class=
                    "term"><code class="filename">libgomp</code></span>
                  </p>
                </td>
                <td>
                  <p>
                    GNU implementation of the OpenMP API for multi-platform
                    shared-memory parallel programming in C/C++ and Fortran
                  </p>
                </td>
              </tr>
              <tr>
                <td>
                  <p>
                    <a id="liblto_plugin" name=
                    "liblto_plugin"></a><span class="term"><code class=
                    "filename">liblto_plugin</code></span>
                  </p>
                </td>
                <td>
                  <p>
                    GCC's Link Time Optimization (LTO) plugin allows GCC to
                    perform optimizations across compilation units.
                  </p>
                </td>
              </tr>
              <tr>
                <td>
                  <p>
                    <a id="libmudflap" name="libmudflap"></a><span class=
                    "term"><code class="filename">libmudflap</code></span>
                  </p>
                </td>
                <td>
                  <p>
                    Contains routines that support GCC's bounds checking
                    functionality
                  </p>
                </td>
              </tr>
              <tr>
                <td>
                  <p>
                    <a id="libquadmath" name="libquadmath"></a><span class=
                    "term"><code class="filename">libquadmath</code></span>
                  </p>
                </td>
                <td>
                  <p>
                    GCC Quad Precision Math Library API
                  </p>
                </td>
              </tr>
              <tr>
                <td>
                  <p>
                    <a id="libssp" name="libssp"></a><span class=
                    "term"><code class="filename">libssp</code></span>
                  </p>
                </td>
                <td>
                  <p>
                    Contains routines supporting GCC's stack-smashing
                    protection functionality
                  </p>
                </td>
              </tr>
              <tr>
                <td>
                  <p>
                    <a id="libstdc" name="libstdc"></a><span class=
                    "term"><code class="filename">libstdc++</code></span>
                  </p>
                </td>
                <td>
                  <p>
                    The standard C++ library
                  </p>
                </td>
              </tr>
              <tr>
                <td>
                  <p>
                    <a id="libsupc" name="libsupc"></a><span class=
                    "term"><code class="filename">libsupc++</code></span>
                  </p>
                </td>
                <td>
                  <p>
                    Provides supporting routines for the C++ programming
                    language
                  </p>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
    <div class="navfooter">
      <ul>
        <li class="prev">
          <a accesskey="p" href="mpc.html" title="MPC-1.0.1">Prev</a>
          <p>
            MPC-1.0.1
          </p>
        </li>
        <li class="next">
          <a accesskey="n" href="sed.html" title="Sed-4.2.2">Next</a>
          <p>
            Sed-4.2.2
          </p>
        </li>
        <li class="up">
          <a accesskey="u" href="chapter06.html" title=
          "Chapter&nbsp;6.&nbsp;Installing Basic System Software">Up</a>
        </li>
        <li class="home">
          <a accesskey="h" href="../index.html" title=
          "Linux From Scratch - Version 7.3">Home</a>
        </li>
      </ul>
    </div>
  </body>
</html>
